package com.star.commonlib.utils.timer

import android.annotation.SuppressLint
import android.os.CountDownTimer
import android.widget.TextView

/**
 *  @des:验证码计时器
 *  TextView-布局
 *  endDes-结束语
 *  millisInFuture-时长
 *  countDownInterval-间隔
 *  @author: sam
 *  @date: 2021/1/18
 */
class StarCountTimer(
    var textView: TextView,
    var endDes: String,
    millisInFuture: Long,
    countDownInterval: Long
) : CountDownTimer(millisInFuture, countDownInterval) {

    /**
     * 开始计时
     * 时间：毫秒millis
     */
    @SuppressLint("SetTextI18n")
    override fun onTick(t: Long) {
        textView.isEnabled = false
        textView.text = (t / 1000).toString() + "s"
    }

    /**
     * 结束
     */
    override fun onFinish() {
        textView.isEnabled = true
        textView.text = endDes
    }
}